package com.whu.waterworks.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.orm.hibernate4.HibernateTemplate;

import com.whu.waterworks.dao.GisStationHistoryDataDao;
import com.whu.waterworks.model.Historydata;

public class GisStationHistoryDataImpl implements GisStationHistoryDataDao {
	private HibernateTemplate hibernateTemplate;
	@Override
	public List<Historydata> findByIdInTimetenRecords(String id, String type,
			String endTime, String beginTime) {
		// TODO Auto-generated method stub
		
		final String hql = "from Historydata rd where rd.id.stationnum='"+id+"' and rd.id.type like '%"+type
				+"%' and rd.id.time>='"+beginTime+"' and rd.id.time<='"+endTime +
				"' order by rd.id.time desc ";
		return this.getHibernateTemplate().execute( new HibernateCallback<List<Historydata>>() {

			@Override
			
			public List<Historydata> doInHibernate(Session session)
					throws HibernateException {
				// TODO Auto-generated method stub
			    final Query query = session.createQuery(hql);
			    query.setMaxResults(10);
			    query.setFirstResult(0);    
			    return (List<Historydata>)query.list();
			}
		});
		

	}
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
	

}
